﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>系统设置</title>
    <link rel="stylesheet" type="text/css" href="~/Content/jquery-easyui-1.4.2/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="~/Content/jquery-easyui-1.4.2/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="~/Content/jquery-easyui-1.4.2/demo.css">
    <link href="~/Content/Styles/Manage_Order.css" rel="stylesheet" />
    <script type="text/javascript" src="~/Content/jquery-easyui-1.4.2/jquery.min.js"></script>
    <script type="text/javascript" src="~/Content/jquery-easyui-1.4.2/jquery.easyui.min.js"></script>
    <script src="~/Content/jquery-easyui-1.4.2/locale/easyui-lang-zh_CN.js"></script>
    <script>
        var postData = {
            ComOpen: 0,// 是否开启评论
            IntOpenPT: 0,// 是否允许平台积分消费
            IntOpenSH: 0,// 是否允许商户积分消费
            IntShOpen: 0,// 是否允许商户开启积分
            TopMer: 0//排序的方式
        }
        $(function () {
            // 获取设置信息
            GetInfo();
            $("#Select1").combobox({
                onChange: function (newvalue, oldvalue) {
                    if (newvalue == 0) {
                        document.getElementById("tableDiv").style.display = "block";
                        initTableNew();// 商户置顶设置

                    }
                    else {
                        document.getElementById("tableDiv").style.display = "none";
                    }
                }

            });
        });
        //获取设置信息，并显示具体设置
        function GetInfo() {
            $.get('/SystemSet/GetOrder_Key', {}, function (database) {
                //console.log(database[0]);
                // 是否允许商户开启积分
                var cb_jifen = document.getElementById("cb_jifen");
                if (database[0].IntShOpen == 1) {
                    cb_jifen.checked = true;
                }
                else {
                    cb_jifen.checked = false;
                }
                // 是否允许平台积分消费
                var cb_ptjifen = document.getElementById("cb_ptjifen");
                if (database[0].IntOpenPT == 1) {
                    cb_ptjifen.checked = true;
                }
                else {
                    cb_ptjifen.checked = false;
                }
                // 是否开启评论
                var cb_pinglun = document.getElementById("cb_pinglun");
                if (database[0].ComOpen == 1) {
                    cb_pinglun.checked = true;
                }
                else {
                    cb_pinglun.checked = false;
                }
                // 是否允许商户积分消费
                var cb_shjifen = document.getElementById("cb_shjifen");
                if (database[0].IntOpenSH == 1) {
                    cb_shjifen.checked = true;
                }
                else {
                    cb_shjifen.checked = false;
                }
                //排序的方式
                var topmer = database[0].TopMer;//
                postData.TopMer = database[0].TopMer;
                if (topmer != "") {
                    var setvalue = topmer.substr(0, 1);
                    $('#Select1').combobox("select", setvalue);
                    if (setvalue == 0) {
                        initTable(postData.TopMer);// 商户置顶设置
                    }
                }
            });
        }

        //修改用户绑定事件
        function BindUpdateOperClickEvent() {

            var cb_jifen = document.getElementById("cb_jifen");// 是否允许商户开启积分
            var cb_ptjifen = document.getElementById("cb_ptjifen");// 是否允许平台积分消费
            var cb_pinglun = document.getElementById("cb_pinglun");// 是否开启评论
            var cb_shjifen = document.getElementById("cb_shjifen");// 是否允许商户积分消费

            // 是否允许商户开启积分
            if (cb_jifen.checked == true) {
                postData.IntShOpen = 1;
            } else {
                postData.IntShOpen = 0;
            }
            // 是否允许平台积分消费
            if (cb_ptjifen.checked == true) {
                postData.IntOpenPT = 1;
            } else {
                postData.IntOpenPT = 0;
            }
            // 是否开启评论
            if (cb_pinglun.checked == true) {
                postData.ComOpen = 1;
            } else {
                postData.ComOpen = 0;
            }
            // 是否允许商户积分消费
            if (cb_shjifen.checked == true) {
                postData.IntOpenSH = 1;
            } else {
                postData.IntOpenSH = 0;
            }
            //商户排位设置
            var top = $("#Select1").combobox("getValue");
            if (top == "0") {
                var rows = $("#shanghuliebiao").datagrid("getRows");
                top = top + '@@';
                for (var item in rows) {
                    top += rows[item].MerID + ",";
                }
                top = top.substr(0, top.length - 1);
                postData.TopMer = top;
                //alert(postData.TopMer);
            }
            else {
                postData.TopMer = top + '@@';
                //alert(postData.TopMer);
            }

            //使用异步实现修改用户信息
            $.post("/SystemSet/Update", postData, function (data) {
                if (data == "1") {
                    $.messager.alert("提示", "保存成功");// 刷新界面
                }
                else if (data == "-1") {  //czx: Session超时异常，直接跳转到登录页面

                    $.messager.alert("提示", "登录超时异常", "warning", function () {
                        window.location.href = "../../login/loginpage";

                    });

                }
                else {
                    $.messager.alert("提示", data);
                }

            });
        }
        //从普通排序切换到自定义排序
        function initTableNew() {
            $('#shanghuliebiao').datagrid({
                iconCls: 'icon-user',
                loadMsg: '数据加载中...',
                nowrap: true,
                autoRowHeight: true,
                singleSelect: true,
                striped: true,
                url: '/SystemSet/mysort',
                border: true,
                remoteSort: false,
                idField: 'MerID',
                pageSize: 100,
                pageList: [100],
                pagination: true,
                rownumbers: true,
                columns: [[
                    { field: 'MerID', title: '商户ID', width: 70, sortable: true },//, hidden: true
                    { field: 'MerName', title: '商户名称', sortable: true },
                    {
                        field: 'ctr', title: '操作', width: 100, align: 'center', formatter: function () {
                            return '<a href="javascript:void(MoveUp())" >上移</a>     <a href="javascript:void(MoveDown())">下移</a>';
                        }
                    }
                ]],
                toolbar: '#tb1',
            });
        }

        //根据商户获取对应的表格
        function initTable(topmer) {
            $('#shanghuliebiao').datagrid({
                iconCls: 'icon-user',
                loadMsg: '数据加载中...',
                nowrap: true,
                autoRowHeight: true,
                singleSelect: true,
                striped: true,
                url: '/SystemSet/getgrid?TopMer=' + topmer,
                border: true,
                remoteSort: false,
                idField: 'MerID',
                pageSize: 100,
                pageList: [100],
                pagination: true,
                rownumbers: true,
                columns: [[
                    { field: 'MerID', title: '商户ID', width: 70, sortable: true },//, hidden: true
                    { field: 'MerName', title: '商户名称', sortable: true },
                    {
                        field: 'ctr', title: '操作', width: 100, align: 'center', formatter: function () {
                            return '<a href="javascript:void(MoveUp())" >上移</a>     <a href="javascript:void(MoveDown())">下移</a>';
                        }
                    }
                ]],
                toolbar: '#tb1',
            });
        }
        //上移
        function MoveUp() {
            console.log("up");
            var row = $("#shanghuliebiao").datagrid('getSelected');
            console.log(row);
            var index = $("#shanghuliebiao").datagrid('getRowIndex', row);
            console.log(index);
            mysort(index, 'up', 'shanghuliebiao');

        }
        //下移
        function MoveDown() {
            var row = $("#shanghuliebiao").datagrid('getSelected');
            var index = $("#shanghuliebiao").datagrid('getRowIndex', row);
            mysort(index, 'down', 'shanghuliebiao');

        }
        //上下移动方法
        function mysort(index, type, gridname) {
            if ("up" == type) {
                if (index != 0) {
                    var toup = $('#' + gridname).datagrid('getData').rows[index];
                    var todown = $('#' + gridname).datagrid('getData').rows[index - 1];
                    $('#' + gridname).datagrid('getData').rows[index] = todown;
                    $('#' + gridname).datagrid('getData').rows[index - 1] = toup;
                    $('#' + gridname).datagrid('refreshRow', index);
                    $('#' + gridname).datagrid('refreshRow', index - 1);
                    $('#' + gridname).datagrid('selectRow', index - 1);
                }
            } else if ("down" == type) {
                var rows = $('#' + gridname).datagrid('getRows').length;
                if (index != rows - 1) {
                    var todown = $('#' + gridname).datagrid('getData').rows[index];
                    var toup = $('#' + gridname).datagrid('getData').rows[index + 1];
                    $('#' + gridname).datagrid('getData').rows[index + 1] = todown;
                    $('#' + gridname).datagrid('getData').rows[index] = toup;
                    $('#' + gridname).datagrid('refreshRow', index);
                    $('#' + gridname).datagrid('refreshRow', index + 1);
                    $('#' + gridname).datagrid('selectRow', index + 1);
                }
            }

        }
    </script>
</head>
<body style="padding: 0;">
    <center>
        <br />
        <br />
        <table style="width:500px" >
            <tr>
                <td colspan="2" style="padding:10px">
                    <font style="font-size:16px"><input id="cb_jifen" type="checkbox" />是否允许商户开启积分</font></td>
            </tr>
            <tr>
                <td colspan="2" style="padding:10px">
                    <font style="font-size:16px"><input id="cb_ptjifen" type="checkbox" />是否允许平台积分消费</font></td>
            </tr>
            <tr>
               <td colspan="2" style="padding:10px">
                    <font style="font-size:16px"><input id="cb_shjifen" type="checkbox" />是否允许商户积分消费</font></td>
            </tr>
            <tr>
                <td colspan="2" style="padding:10px">
                    <font style="font-size:16px"><input id="cb_pinglun" type="checkbox" />是否允许评论</font></td>
            </tr>
            <tr>
                <td width="130px" style="padding:10px 0 10px 10px"><font style="font-size:16px">商户排位设置：</font></td>
                <td  style="padding:10px 10px 10px 0">
                    <select id="Select1" style="font-size:14px" >
                        <option value="0">自定义</option>
                        <option value="1">销量总数</option>
                        <option value="2">评论总数</option>
                        <option value="3">星级总数</option>
                    </select></td>
            </tr>
            <tr>
               <td colspan="2" style="padding:10px">
                    <div id="tableDiv"><table id="shanghuliebiao"></table></div>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    &nbsp;
                <td>
            </tr>
            <tr>
                <td colspan="2">
                    &nbsp;
                <td>
            </tr>
            <tr>
                <td colspan="2" style="padding-left: 45px;" >
                    <a id="btnUpdate"  class="easyui-linkbutton" data-options="iconCls:'icon-edit'" onclick="BindUpdateOperClickEvent()">保存</a>
                    &nbsp;&nbsp;&nbsp;&nbsp;
                    @*<a id="btnCancel" href="javascript:(0)" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'">取消</a>*@
                </td>
            </tr>
        </table>
    </center>
</body>
</html>

